<?php
namespace PublicNo\Model;
use Think\Model;
class PublicNoMsgModel extends Model {
	protected $connection = 'DB_BASE_DSN';
	protected $tableName = 'qyx_publicno_msg'; 
	
	
	public function getMsgList($data){
		$map = array();
	
		if(!empty($data['publicnoid'])){
			$map['publicnoid'] = $data['publicnoid'];
		}
	
		$total = $this->where($map)->count();
		$fields = array('id','publicnoid','type','itemscontent','createtime','updatetime');
	
		if(empty($data['sortField']))$data['sortField'] = "id";
		if(empty($data['sortOrder']))$data['sortOrder'] = "desc";
	
		if(empty($data['pageSize']) && empty($data['pageIndex']))
			$result = $this->field($fields)->where($map)->order("{$data['sortField']} {$data['sortOrder']}")->select();
		else
			$result = $this->field($fields)->where($map)->order("{$data['sortField']} {$data['sortOrder']}")->limit($data['pageIndex']*$data['pageSize'] , $data['pageSize'])->select();
	
		$pages = ($total==0) ? 0 : (!empty($data['pageSize']) ? ceil($total/$data['pageSize']) : 1);
		
		return array('total'=>$total , 'data'=>$result , 'pages'=>$pages);
	}
	
	public function addMsg($data){
		$result = $this->add($data);
		return $result;
	}
	
}


